<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    #container{
        width: 360px;
        min-height: 100px;
        background-color: lightgreen;
        position: absolute;
        left: 50%;
        top: 10px;
        margin-left: -180px;
    }
    </style>
    <script type="text/javascript" src="./ajax.js"></script>
    <script type="text/javascript">
    /*
    功能需求：页面输入图书编号，查询服务器端的图书信息并且解析渲染
    */
    window.onload = function(){
        var btn = document.getElementById('btn');
        btn.onclick = function(){
            var code = document.getElementById('code').value;
            ajax('./selectbook.php','get','code='+code,'json',function(data){
                // 解析数据并渲染页面
                var info = document.getElementById('info');
                if(data.flag == 0){//没有查询到数据
                    info.innerHTML = '没有这本书';
                }else{
                    var tag = '<ul><li>书名：'+data.bookname+'</li><li>作者：'+data.author+'</li><li>描述：'+data.desc+'</li></ul>';
                    info.innerHTML = tag;
                }

            });
        }
    }
    </script>
</head>
<body>
    <div id="container">
        <div>
            图书编码：<input type="text" name="code" id="code">
            <input type="button" value="查询" id="btn">
        </div>
        <div id="info"></div>
    </div>
</body>
</html>



<!--<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			
		</style>
		<script type="text/javascript" src="./ajax.js"></script>
		<script type="text/javascript">
			window.onload=function(){
//				获取按钮
				var btn=document.getElementById('btn');
//				按钮点击时,进行查询
				btn.onclick=function(){
					var val=document.getElementById('valbook').value;
					ajax('./selectbook.php','get','val='+val,'json',function(data){
						//解析数据并渲染页面
						var lbook =document.getElementById('listbook');
						if(data.flag==0){
							lbook.innerHTML='没有查询到要搜索的书'
						}else{
							var tag='<ul><li>书名：'+data.bookname
							           +'</li><li>作者：'+data.author
							           +'</li><li>描述：'+data.desc
							           +'</li></ul>';
							lbook.innerHTML=tag;
						}
					})
				}
			}
		</script>
	</head>
	<body>
		<div id="container">
				请输入书名：<input type="text" name="valbook" id="valbook" value="" />
				<input type="button" id="btn" value="查询"/>
			<div id="listbook"></div>
		</div>
	</body>
</html>-->
